package com.viewsky.base.back.util;


import java.util.Date;
import java.util.Map;

import org.springframework.stereotype.Component;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

@Component
public class JwtUtil 
{	
	public static String generateToken(Map<String, Object> mapClaim, Date expiration)
	{	
		String strToken = Jwts.builder()
				.setClaims(mapClaim)
				.signWith(SignatureAlgorithm.HS256, Constant.DEF_JWT_SECRET)
				.setExpiration(expiration)
				.compact();
		
		return strToken;
	}
	
	public static Claims decodeToken(String strToken)
	{
		Claims claims = Jwts.parser().setSigningKey(Constant.DEF_JWT_SECRET)
				.parseClaimsJws(strToken).getBody();
		
		return claims;
	}
}
